from django.db import models
from datetime import datetime

# Create your models here.
#用户信息模型
class Users(models.Model):
    username = models.CharField(max_length=32)
    name = models.CharField(max_length=16)
    password = models.CharField(max_length=32)
    sex = models.IntegerField(default=1)
    address = models.CharField(max_length=255)
    code = models.CharField(max_length=6)
    phone = models.CharField(max_length=16)
    email = models.CharField(max_length=50)
    state = models.IntegerField(default=1)
    addtime = models.DateTimeField(default=datetime.now)

    def toDict(self):
        return {'id':self.id,'username':self.username,'name':self.name,'password':self.password,'address':self.address,'phone':self.phone,'email':self.email,'state':self.state}

    class Meta:
        db_table = "users"  # 更改表名


#主机信息模型
class Hosts(models.Model):
    tag = models.CharField(max_length=64)
    ip = models.CharField(max_length=32)
    cpu = models.IntegerField(default=0)
    memory = models.FloatField(default=0)
    disk = models.FloatField(default=0)
    addtime = models.DateTimeField(default=datetime.now)
    state = models.IntegerField(default=1)

    def toDict(self):
        return {'id':self.id,'ip':self.ip,'cpu':self.cpu,'memory':self.memory,'disk':self.disk,'addtime':self.addtime,'state':self.state}

    class Meta:
        db_table = "hosts"  # 更改表名

#CPU使用率信息模型
class CpuRate(models.Model):
    ip = models.CharField(max_length=32)
    percent = models.FloatField(default=0)
    addtime = models.DateTimeField(default=datetime.now)

    class Meta:
        db_table = "cpu_rate"  # 更改表名

#内存使用率信息模型
class MemRate(models.Model):
    ip = models.CharField(max_length=32)
    percent = models.FloatField(default=0)
    addtime = models.DateTimeField(default=datetime.now)

    class Meta:
        db_table = "mem_rate"  # 更改表名

#硬盘使用率信息模型
class DiskRate(models.Model):
    ip = models.CharField(max_length=32)
    percent = models.FloatField(default=0)
    addtime = models.DateTimeField(default=datetime.now)

    class Meta:
        db_table = "disk_rate"  # 更改表名
